{include file='common/head.html'}
<div class="layui-body">
    {if([$list])}
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="t1">表单列表</li>
            <li lay-id="t2">表单新增</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table class="layui-table">
                    <thead>
                        <tr>
                            <th>编码</th>
                            <th>表单名称</th>
                            <th>表名称</th>
                            <th>数据</th>
                            <th>字段</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $forms(key,value)}
                        <tr>
                            <td>[value->fcode]</td>
                            <td>[value->form_name]</td>
                            <td>[value->table_name]</td>
                            <td>
                                {if($value->id==1)}
                                <a href="{url./admin/Message/index}"><i class="fa fa-list"></i> 查看数据</a></td>
                            {else}
                            <a href="{url./admin/Form/index/fcode/'.$value->fcode.'/action/showdata}"><i class="fa fa-list"></i> 查看数据</a></td>
                            {/if}
                            <td><a href="{url./admin/Form/index/fcode/'.$value->fcode.'/action/showfield}"><i class="fa fa-pencil-square-o"></i> 编辑字段</a></td>
                            <td>
                                {if($value->id!=1)}
                                <a href="{url./admin/Form/mod/id/'.$value->id.'/action/addmenu}{$btnqs}" class="layui-btn layui-btn-xs layui-btn-primary">添加到菜单</a>
                                <a href='javascript:confirm_delete("{url./admin/Form/del/id/'.$value->id.'/action/delform}")' class="layui-btn layui-btn-xs layui-btn-danger" title="删除">删除</a>
                                {/if}
                                <a href="{url./admin/Form/mod/id/'.$value->id.'/action/modform}{$btnqs}" class="layui-btn layui-btn-xs">修改</a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                <div class="page">{$pagebar}</div>
            </div>
            <div class="layui-tab-item">
                <form action="{url./admin/Form/add/action/addform}" method="post" class="layui-form">
                    <input type="hidden" name="formcheck" value="{$formcheck}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">表单名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="form_name" maxlength=20 required lay-verify="required" placeholder="请输入表单名称，如：报名表" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">表名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="table_name" maxlength=30 required lay-verify="required" placeholder="请输入表名称，如：baoming" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit>立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {/if}
    {if([$showdata])}
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="t1">{$form->form_name} — 数据</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <!-- 搜索 -->
                <form action="{url./admin/Form/index/fcode/'.[$form->fcode].'}" method="get" class="layui-form">
                    <div class="layui-form-item nospace">
                        <div class="layui-input-inline">
                            {$pathinfo}
                            {php}$type = get('type');{/php}
                            <select name="type">
                                <option value="">全部</option>
                                {foreach $fields(key2,value2,num2)}
                                <option value="[value2->name]" {if($value2->name==$type)}selected="selected"{/if}>[value2->description]</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword" value="{$get.keyword}" placeholder="请输入搜索关键字" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit onclick="submit();">搜索</button>
                            <a class="layui-btn layui-btn-primary" href="{url./admin/Form/index/fcode/'.[$form->fcode].'/action/showdata}">清除搜索</a>
                        </div>
                    </div>
                </form>
                <!-- 列表显示 -->
                <form action="{url./admin/Form/del/fcode/'.[$form->fcode].'}/action/deldata" method="post" id="contentForm" name="contentForm" class="layui-form" onkeydown="if(event.keyCode==13) return false;">
                    <input type="hidden" name="formcheck" value="{$formcheck}">
                    <table class="layui-table">
                        <thead>
                            <tr>
                                <th width="10"><input type="checkbox" class="checkbox" lay-ignore id="checkall" title="全选"></th>
                                <th width="30">序号</th>
                                {foreach $fields(key2,value2,num2)}
                                {if($value2->is_list)}
                                <th>[value2->description]</th>
                                {/if}
                                {/foreach}
                                <th width="150">时间</th>
                                <th width="60">是否阅读</th>
                                <th width="150">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $formdata(key,value,num)}
                            <tr>
                                <td><input type="checkbox" class="checkbox checkitem" lay-ignore name="list[]" value="[value->id]" id="checka"></td>
                                <td>{php}echo $numdesc = [$pagerows]-$num+1;{/php}</td>
                                {foreach $fields(key2,value2,num2)}
                                {php} $field=$value2->name;{/php}
                                {if($value2->is_list)}
                                {if(preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $value->$field))}
                                <td><a href='[value->$field]' target='_blank'><img src='[value->$field]' width='30' height='30' style='float: unset;cursor: pointer;' /></a></td>
                                {/if}
                                {if(preg_match('/(\.(zip|gz|rar|iso|doc|xsl|ppt|wps|docx|xslx|pdf))$/i', $value->$field))}
                                {php}$arr=explode("/", $value->$field);$last=$arr[count($arr)-1];{/php}
                                <td><a href='[value->$field]' target='_blank'>{php}echo $last;{/php}</a></td>
                                {/if}
                                {if(!preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp|zip|gz|rar|iso|doc|xsl|ppt|wps|docx|xslx|pdf))$/i', $value->$field))}
                                <td>[value->$field]</td>
                                {/if}
                                {/if}
                                {/foreach}
                                <td>[value->create_time]</td>
                                <td>
                                    {if($value->view_status)}
                                    <a href="{url./admin/Form/submod/id/'.$value->id.'/table/'.[$form->table_name].'/field/view_status/value/0}"><i class='fa fa-toggle-on' style="vertical-align:middle"></i></a>
                                    {else}
                                    <a href="{url./admin/Form/submod/id/'.$value->id.'/table/'.[$form->table_name].'/field/view_status/value/1}"><i class='fa fa-toggle-off' style="vertical-align:middle"></i></a>
                                    {/if}
                                </td>
                                <td>
                                    {fun=get_btn('详细','','submod',$value->id.'/fcode/'.[$form->fcode].'/table/'.[$form->table_name])}
                                    <a href='javascript:confirm_delete("{url./admin/Form/del/id/'.$value->id.'/fcode/'.[$form->fcode].'/action/deldata}")' class="layui-btn layui-btn-xs layui-btn-danger" style="margin-bottom:0px" title="删除">删除</a>
                                </td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>
                    <div class="layui-btn-group">
                        <button type="submit" name="submit" onclick="return setDelAction();" class="layui-btn layui-btn-sm layui-btn-primary">批量删除</button>
                        {if(session('ucode')==10001 && [$formdata])}
                        <a href="{url./admin/Form/clear/fcode/'.[$form->fcode].'}" onclick='return confirm("您确定要清空么？")' class="layui-btn layui-btn-sm layui-btn-primary">清空全部记录</a>
                        {/if}
                        {if([$formdata])}
                        <a href="{url./admin/Form/index/fcode/'.[$form->fcode].'/action/showdata/export/1}" class="layui-btn layui-btn-sm layui-btn-primary">导出全部记录</a>
                        {/if}
                    </div>
                    <div class="page">{$pagebar}</div>
                </form>
            </div>
        </div>
    </div>
    <script>
        function setDelAction(){
	          document.contentForm.action = "{url./admin/Form/dellist/fcode/'.[$form->fcode].'}"; 
	          return confirm("您确定要删除选中的内容么？");
	      }
	  </script>
    {/if}
     {if([$submod])}
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this">{$form->form_name}详情</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                    <table class="layui-table table-two">
                        <tbody>

                            {foreach $fields(key2,value2,num2)}
                            <tr>
                                <th>[value2->description]</th>
                                {php} $field=$value2->name {/php}
                                <td>
                                    {foreach $messages(key,value,num)}
                                    {if($value2->name == $key)}
                                    {if(preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $value))}
                                    <a href='[value]' target='_blank'><img src='[value]' width='60' height='60' style='float: unset;cursor: pointer;' /></a>
                                    {/if}
                                    {if(preg_match('/(\.(zip|gz|rar|iso|doc|xsl|ppt|wps|docx|xslx|pdf))$/i', $value))}
                                    {php}$arr=explode("/", $value);$last=$arr[count($arr)-1];{/php}
                                    <a href='[value]' target='_blank'>{php}echo $last;{/php}</a>
                                    {/if}
                                    {if(!preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp|zip|gz|rar|iso|doc|xsl|ppt|wps|docx|xslx|pdf))$/i', $value))}
                                    [value]
                                    {/if}
                                    {/if}
                                    {/foreach}
                                </td>
                            </tr>
                            {/foreach}
                            <tr>
                                <th>时间</th>
                                <td>{$messages->create_time}</td>
                            </tr>
                            <tr>
                                <th>访客信息</th>
                                <td>
                                    IP:<a href="http://ip.taobao.com/ipSearch.html?ipAddr={fun=long2ip([$messages->user_ip])}" target="_blank" title="点击查看归属地">{fun=long2ip([$messages->user_ip])}</a>；
                                    浏览器:{$messages->user_bs}；
                                    操作系统:{$messages->user_os}
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            {fun=get_btn_back()}
                        </div>
                    </div>
            </div>
        </div>
    </div>
    {/if}
    {if([$showfield])}
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="t1">{$form->form_name}-表单字段</li>
            <li lay-id="t2">新增字段</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table class="layui-table">
                    <thead>
                        <tr>
                            <th width=40>序号</th>
                            <th>描述</th>
                            <th>字段</th>
                            <th>长度</th>
                            <th>是否必填</th>
                            <th>是否列表显示</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $fields(key,value)}
                        <tr>
                            <td>[num]</td>
                            <td>[value->description]</td>
                            <td>[value->name]</td>
                            <td>[value->length]</td>
                            <td>
                                {if($value->required)}
                                <a href="{url./admin/'.C.'/mod/id/'.$value->id.'/field/required/value/0}"><i class='fa fa-toggle-on' title="点击关闭必填"></i></a>
                                {else}
                                <a href="{url./admin/'.C.'/mod/id/'.$value->id.'/field/required/value/1}"><i class='fa fa-toggle-off' title="点击开启必填"></i></a>
                                {/if}
                            </td>
                            <td>
                                {if($value->is_list)}
                                <a href="{url./admin/'.C.'/mod/id/'.$value->id.'/field/is_list/value/0}"><i class='fa fa-toggle-on' title="点击不显示"></i></a>
                                {else}
                                <a href="{url./admin/'.C.'/mod/id/'.$value->id.'/field/is_list/value/1}"><i class='fa fa-toggle-off' title="点击开启显示"></i></a>
                                {/if}
                            </td>
                            <td>[value->sorting]</td>
                            <td>
                                <a href="{url./admin/Form/del/id/'.$value->id.'/fcode/'.[$get.fcode].'}" onclick="return confirm('您确定要删除么？')" class="layui-btn layui-btn-xs layui-btn-danger" title="删除">删除</a>
                                {fun=get_btn_mod($value->id)}
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                <div class="page">{$pagebar}</div>
                <div><a href="{url./admin/Form/index}" class="layui-btn">返回表单</a></div>
            </div>
            <div class="layui-tab-item">
                <form action="{url./admin/Form/add}" method="post" class="layui-form">
                    <input type="hidden" name="formcheck" value="{$formcheck}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段描述</label>
                        <div class="layui-input-block">
                            <input type="hidden" value="{$get.fcode}" name="fcode">
                            <input type="text" name="description" required lay-verify="required" placeholder="请输入字段描述，如：联系人" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" required maxlength="20" lay-verify="required" placeholder="请输入字段名称，必须以字母开头，如：contacts" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段长度</label>
                        <div class="layui-input-block">
                            <input type="text" name="length" value="20" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否必填</label>
                        <div class="layui-input-block">
                            <input type="radio" name="required" value="1" title="必填" checked>
                            <input type="radio" name="required" value="0" title="非必填" checked>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否列表显示</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_list" value="1" title="显示" checked>
                            <input type="radio" name="is_list" value="0" title="不显示" checked>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sorting" value="255" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit>立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {/if}
    
    {if(@[$mod])}
    {if([$form])}
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this">自定义表单修改</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form action="{url./admin/Form/mod/id/'.[$get.id].'/action/modform}{$backurl}" method="post" class="layui-form">
                    <input type="hidden" name="formcheck" value="{$formcheck}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">表单名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="form_name" maxlength=20 required value="{$form->form_name}" lay-verify="required" placeholder="请输入表单名称，如：报名表" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">表名称</label>
                        <div class="layui-input-block">
                            <input type="text" maxlength=30 required readonly value="{$form->table_name}" lay-verify="required" placeholder="请输入表名称，如：baoming" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit>立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            {fun=get_btn_back()}
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {/if}
    {if(@[$field])}
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this">表单字段修改</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form action="{url./admin/Form/mod/id/'.[$get.id].'}{$backurl}" method="post" class="layui-form">
                    <input type="hidden" name="formcheck" value="{$formcheck}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段描述</label>
                        <div class="layui-input-block">
                            <input type="text" name="description" value="{$field->description}" placeholder="请输入字段描述，如：联系人" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" readonly value="{$field->name}" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段长度</label>
                        <div class="layui-input-block">
                            <input type="text" name="length" readonly value="{$field->length}" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否必填</label>
                        <div class="layui-input-block">
                            <input type="radio" name="required" value="1" title="必填" {if([$field->required]==1)}checked{/if}>
                            <input type="radio" name="required" value="0" title="非必填" {if([$field->required]==0)}checked{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否列表显示</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_list" value="1" title="显示" {if([$field->is_list]==1)}checked{/if}>
                            <input type="radio" name="is_list" value="0" title="不显示" {if([$field->is_list]==0)}checked{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sorting" value="{$field->sorting}" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit>立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            {fun=get_btn_back()}
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {/if}
    {/if}
</div>
{include file='common/foot.html'}